#include<stdio.h>
#include<stdlib.h>
#include<string.h>

/*
    about malloc and realloc, in array, store.
    realloc is really a shit.
*/

int main(int argc, char const *argv[])
{
    int arr[] = {1, 2, 3, 4, 5, 6};
    int *arr1;
    arr1 = (int*)malloc(6 * sizeof(int));
    for(int i = 0; i < 6; i++) {
        arr1[i] = i+1;
    }
    printf("arr is below:\n");
    for(int i = 0; i < 6; i++) {
        printf("%d ", arr[i]);
    }
    printf("\narr1 is below:\n");
    for(int i = 0; i < 6; i++) {
        printf("%d ", arr1[i]);
    }
    
    // printf("\nnow we realloc arr:\n");
    // arr = (int*)realloc(arr, 10 * sizeof(int)); 
    //this is a static array, it can't be realloc!

    printf("\nwe realloc arr1:\n");
    arr1 = (int*)realloc(arr1, 10 * sizeof(int));
    // printf("the length of arr1:%d", strlen(arr1)); //can't, strlen must be a string!
    printf("now visit ");
    arr1[8] = 9;
    arr1[16] = 16;
    arr1[88] = 88;
    printf("\narr1[8] = %d", arr1[8]);
    printf("\narr1[16] = %d", arr1[16]);
    printf("\narr1[88] = %d", arr1[88]);
    return 0;
}
